<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    #item{
        width: 350px;
        height: 100px;
        line-height: 100px;
        border-bottom: 1px solid #999999;
    }
    img{
        width: 100px;
        float: left;
    }
</style>
<body>
<div id="app">
    <input type="text" name="" id="" placeholder="请输入要查找的书籍" v-model="searchStr">
    <div id="item" v-for="book in searchBook">
        <img :src="book.src">
        <span>{{book.name}}</span>
    </div>
</div>
</body>
</html>
<script>
    new Vue({
        el: '#app',
        data: {
            books:[
                {src:'../img/c.png',name:'C语言'},
                {src:'../img/htmlcss.png',name: 'html'},
                {src:'../img/htmlcss200.png',name:'htmlcss'},
                {src:'../img/java200.png',name: 'java'},
                {src:'../img/javascript.png',name: 'javascript'},
            ],
            searchStr:''
        },
        computed:{
            searchBook(){
                var books=this.books
                let searchStr = this.searchStr.trim().toLowerCase();
                books = books.filter(function(item){
                    if (item.name.toLowerCase().indexOf(searchStr)!=-1){
                        return item;
                    }
                })
                return books
            }
        }
    })
</script>
